package com.maniu.jnimaniu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.maniu.jnimaniu.databinding.ActivityMainBinding;

import org.w3c.dom.Text;

import java.lang.reflect.Field;

public class MainActivity extends AppCompatActivity {
//    秘钥     数据  接口    解答

    //     秘钥
    String data = "";
    static {
        System.loadLibrary("jnimaniu");
    }
//int   double
    public  String text = "码牛";
    TextView sample_text;
    Bitmap bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sample_text = findViewById(R.id.sample_text);
        sample_text.setText(text);
    }

//C++  前面     C 函数 后面 2  静态注入
//    Java_com_maniu_jnimaniu_MainActivity_func1
    public native void func1();

    public native void func2(String data);

    public native String func3();
    public native void func4();
    public void func1(View view) {
        func1();
    }
    public void func2(View view) {
        func2("data");
    }
    public void func3(View view) {


        func4();
        sample_text.setText(text);
    }

    public native void func5();
    public void func4(View view) {
        init();
        func5();
    }
    public String getSignInfo() {
        try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(
                    getPackageName(), PackageManager.GET_SIGNATURES);
            Signature[] signs = packageInfo.signatures;
            Signature sign = signs[0];
            return sign.toCharsString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void func5(View view) {
        sample_text.setText(getKey());
        Log.i("david", "func5: " + getSignInfo());
        setAntiBiBCallback(new IAntiDebugCallback() {
            @Override
            public void beInjectedDebug() {

            }
        });
    }
    public void callBack(int code){
        Toast.makeText(this, "native层回调  " + code, Toast.LENGTH_SHORT).show();
    }
    public void callBack(byte[] code){
        Toast.makeText(this, "native层回调  " + code, Toast.LENGTH_SHORT).show();
    }
//
    public String callBack(String code,int code1){
        Toast.makeText(this, "native层回调  " + code, Toast.LENGTH_SHORT).show();
        return null;
    }
//  1s  100次   静态2   动态 1
    public native void setAntiBiBCallback(IAntiDebugCallback callback);
    public static native boolean init();

    /**
     * 99%   验证app  我们
     *
     * 1% 的   代码 ket
     *
     * @return return key
     */
    public static native String getKey();

}